/*
 * @Author: MrDotYan 2564217790@qq.com
 * @Date: 2024-09-19 14:28:26
 * @LastEditors: MrDotYan 2564217790@qq.com
 * @LastEditTime: 2024-09-25 14:34:30
 * @FilePath: /webServer/src/socket/index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Context } from '@midwayjs/socketio';
import {
  WSController,
  Inject,
  OnWSConnection,
  WSEmit,
  OnWSDisConnection,
} from '@midwayjs/core';
import { useSuccess } from '../utils/resHelper';

@WSController('/global')
export class SocketController {
  @Inject()
  ctx: Context;

  @OnWSConnection()
  @WSEmit('onConnected')
  async onConnectionMethod() {
    this.ctx.logger.info(`Socket [${this.ctx.id}]： 已连接`);
    return useSuccess({ socketID: this.ctx.id });
  }

  @OnWSDisConnection()
  async onDisConnection() {
    this.ctx.logger.info(`Socket [${this.ctx.id}]： 已断开`);
  }
}
